<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>users</title>
<jsp:include page="header.jsp"></jsp:include>
<script type="text/javascript">
$(function(){
	//分页显示用户列表
	$('#dg').datagrid({    
	    url:'../shop/show', 
	   		title:'用户列表',
			iconCls:'icon-save',
			fitColumns:true,
			striped:true,
			pagination:true,
			rownumbers:true,
			fit:true,
			columns:[[
			{field:'spic',title:'商铺头像',width:50,height:80,align:'left',
		        formatter:function(value, rec){//使用formatter格式化刷子
		        	return '<img src='+'../images/'+value+'>';
		        }},
	        {field:'sname',title:'商铺名称',width:100},    
	        {field:'summary',title:'商品简介',width:100},
	        {field:'pid',title:'供应商ID',width:100}
	    ]], 
	    toolbar: [{
			iconCls: 'icon-edit',
			handler: updateShop,
			text:'管理商铺信息',
		}]
	}) 
	
});
	//1.更新商铺信息
	function updateShop(){
		//清空form
		$("#updateShop").dialog("open");
		$("#addpic #fb").filebox({    
		    buttonText: '选择文件', 
		    buttonAlign: 'left' 
		})
		//获取老的参数
		var row = $('#dg').datagrid('getSelected');
		$("#updateShop #ff").form("load",row);
		
	}
	function closeAddPicDialog(){
		$("#updateShop").dialog("close");
	}
	function addPicDialog(){
		$("#updateShop #ff").form('submit', {    
		    url:'../shop/update',   
		    onSubmit: function(){    
		        // 做一些验证，提交数据是否合法
		        return $(this).form('validate');  
		    },    
		    success:function(data){ //这个data不是json对象而是一个字符串 
		    	var message=JSON.parse(data);	    
		    	$.messager.show({
					title:'提示消息',
					msg:message.msg,
					timeout:2000,
					showType:'slide'
				});
		    	if(message.success){
		    		$("#dg").datagrid("reload");
		    		$("#updateShop").dialog("close");
		    	}    
		    }    
		}); 
	}
</script>
</head>
<body>
	<table id="dg"></table> 
	<div id="updateShop" class="easyui-dialog" title="管理店铺信息" style="width:600px;padding:10px;"   
        data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true,buttons:[{
				text:'保存',
				handler:addPicDialog
			},{
				text:'关闭',
				handler:closeAddPicDialog
			}]">
	<form id="ff" method="post" enctype="multipart/form-data">
	<table id="addpic">
		<tr><td><input type="hidden" name="sid"></td></tr>
		<tr><td>商铺简介:<input name="summary"></td></tr>
		<tr><td>商铺名称:<input name="sname"></td></tr>
		<tr><td>商铺头像:<input id="fb" type="text" name="spic" style="width:300px"></td></tr>
		<tr><td><input type="hidden" name="pid"></td></tr>
	</table>
	</form>
	</div>
</body>
</html>